package cn.harry.cabinet.viewmodel

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData

/**
 * MVVM架构的基础ViewModel类
 * 提供基本的LiveData支持和应用程序上下文
 */
open class BaseViewModel(application: Application) : AndroidViewModel(application) {
    
    // 添加一个加载状态的LiveData
    private val _loading = MutableLiveData<Boolean>()
    val loading: LiveData<Boolean> = _loading
    
    // 添加一个错误信息的LiveData
    private val _error = MutableLiveData<String>()
    val error: LiveData<String> = _error
    
    /**
     * 显示加载状态
     */
    protected fun showLoading() {
        _loading.value = true
    }
    
    /**
     * 隐藏加载状态
     */
    protected fun hideLoading() {
        _loading.value = false
    }
    
    /**
     * 显示错误信息
     */
    protected fun showError(message: String) {
        _error.value = message
        hideLoading()
    }
}